package com.komodo.island.gdx;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.dialog.Dialog;
import com.komodo.island.gdx.screen.HelpScreen;
import com.komodo.island.gdx.screen.MapScreen;
import com.komodo.island.gdx.screen.Screen;

public class GameDescription extends Dialog {

	public static final int SUIT = 1;
	public static final int PHOTO = 2;
	public static final int UNDERWATER = 5;
	public static final int BALANCE = 0;
	public static final int CASTLE = 4;
	public static final int MOVE = 3;
	public static final int SHOPPING = 6;

	TextureRegion imageDesc;

	TextureRegion descs[];

	int gameChosen;

	Button play;
	Button help;
	Button back;
	Image desc;

	public HelpScreen helpScreen;
	
	public GameDescription(float width, float height, boolean stretch,
			Screen screen, Texture texture, TextureRegion imageDesc, KomodoIsland komodoIsland) {
		super(width, height, stretch, screen, texture, komodoIsland);
		// TODO Auto-generated constructor stub
		ID = Input.DIALOG_GAME_DESC;
		this.imageDesc = imageDesc;
		inits();
	}

	public void inits() {
		helpScreen = new HelpScreen(null, 1, 5000, screen);
		helpScreen.init(screen.komodoIsland, screen.komodoIsland.helpTexture);
		
		
		background = new Image("background", imageDesc);

		// 105 135
		descs = new TextureRegion[7];
		descs[PHOTO] = new TextureRegion(texture, 960, 0, 360, 160);
		descs[MOVE] = new TextureRegion(texture, 960, 160, 360, 160);
		descs[SHOPPING] = new TextureRegion(texture, 960, 160 * 2, 360, 160);
		descs[BALANCE] = new TextureRegion(texture, 960+360, 0, 360, 160);
		descs[CASTLE] = new TextureRegion(texture, 960+360, 160, 360, 160);
		descs[SUIT] = new TextureRegion(texture, 960+360 * 2, 0, 360, 160);
		descs[UNDERWATER] = new TextureRegion(texture, 960+360 * 2, 160, 360, 160);

		desc = new Image("desc", descs[gameChosen]);
		desc.x = 105;
		desc.y = 135;

		back = new Button("back", new TextureRegion(
				screen.komodoIsland.buttonTexture, 90 + 63 + 64 * 4, 200, 32,
				32), new TextureRegion(screen.komodoIsland.buttonTexture, 90
				+ 63 + 64 * 4 + 32, 200, 32, 32));

		help = new Button("help", new TextureRegion(
				screen.komodoIsland.dialogTexture, 351 + 200 + 97, 71 + 28 * 2
						+ 64 + 32, 32, 32), new TextureRegion(
				screen.komodoIsland.dialogTexture, 351 + 200 + 97 + 32, 71 + 28
						* 2 + 64 + 32, 32, 32));

		play = new Button("play", new TextureRegion(
				screen.komodoIsland.dialogTexture, 351 + 200, 71 + 28 * 2, 64,
				64), new TextureRegion(screen.komodoIsland.dialogTexture,
				351 + 200, 71 + 28 * 2, 64, 64));

		play.width = 32;
		play.height = 32;

		play.x = 480 - play.width - 32;
		play.y = 16;

		help.x = play.x - help.width - 32;
		help.y = play.y;

		back.x = 16;
		back.y = 320 - back.height - 16;

		addActor(background);
		addActor(desc);
		addActor(play);
		addActor(help);
		addActor(back);

		play.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
//				System.out.println("PLAY!!");
//				Art.drawString("PLAY", 0, 0);
				if (Persistence.sound)
					screen.komodoIsland.dialogSound.play(1);
				((MapScreen) screen).hideGameDesc();
				screen.komodoIsland.input.removeStage();
				if (gameChosen == MOVE) {
					screen.komodoIsland.gameKomodoMove.startGame();
					screen.komodoIsland
							.goToScreen(screen.komodoIsland.gameKomodoMove);
				} else if (gameChosen == SUIT) {
					screen.komodoIsland.gameSuit.startGame();
					screen.komodoIsland
							.goToScreen(screen.komodoIsland.gameSuit);
				} else if (gameChosen == BALANCE) {
					screen.komodoIsland.gameBalance.startGame();
					screen.komodoIsland
							.goToScreen(screen.komodoIsland.gameBalance);
				} else if (gameChosen == CASTLE) {
					screen.komodoIsland.gameSandCastle.startGame();
					screen.komodoIsland
							.goToScreen(screen.komodoIsland.gameSandCastle);
				} else if (gameChosen == PHOTO) {
					screen.komodoIsland.gameKomodoPhoto.startGame();
					screen.komodoIsland
							.goToScreen(screen.komodoIsland.gameKomodoPhoto);
				
//				else if (gameChosen == SHOPPING) {
//					screen.komodoIsland.gameShopping.startGame();
//					screen.komodoIsland
//							.goToScreen(screen.komodoIsland.gameShopping);
				} else if (gameChosen == UNDERWATER) {
					screen.komodoIsland.gameUnderWater.startGame();
					screen.komodoIsland
							.goToScreen(screen.komodoIsland.gameUnderWater);
				}

			}
		};
		back.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					screen.komodoIsland.dialogSound.play(1);
				((MapScreen) screen).hideGameDesc();
			}
		};
		
		help.clickListener = new Button.ClickListener() {

			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				if (Persistence.sound)
					screen.komodoIsland.dialogSound.play(1);
				screen.komodoIsland.helpScreen.setHelp(gameChosen);
				screen.komodoIsland.helpScreen.nextScreen = screen;
				((MapScreen) screen).komodoIsland.goToScreen(screen.komodoIsland.helpScreen);
				((MapScreen) screen).hideGameDesc();
			}
		};
	}

	public void setChoise(int gameIndex) {
		gameChosen = gameIndex;
		desc.region = descs[gameIndex];
	}

	@Override
	public void addElements() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setThePosition() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setTheListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

}
